
# ifndef __DFX_COLOR4_H__
# define __DFX_COLOR4_H__

# include "dfxCore.h"

namespace DFX
{
    class DFX_EXPORT Color4
    {
    public:

        Float32     R;
        Float32     G;
        Float32     B;
        Float32     A;

    public:

        Color4(Float32 f = 0.0f)
            : R(f), G(f), B(f), A(1.0f)
        {
        }

        Color4(Float32 r, Float32 g, Float32 b, Float32 a = 1.0f)
            : R(r), G(g), B(b), A(a)
        {
        }

        Color4(const Color4 &c)
            : R(c.R), G(c.G), B(c.B), A(c.A)
        {
        }

        inline UInt32 ToUInt32() const
        {
            return ((UInt8)(R * 255.0f)) << 24 |
                   ((UInt8)(G * 255.0f)) << 16 |
                   ((UInt8)(B * 255.0f)) <<  8 |
                   ((UInt8)(A * 255.0f));
        }

        inline UInt32 ToArgb() const
        {
            return ((UInt8)(A * 255.0f)) << 24 |
                   ((UInt8)(R * 255.0f)) << 16 |
                   ((UInt8)(G * 255.0f)) <<  8 |
                   ((UInt8)(B * 255.0f));
        }

        inline UInt32 ToBgra() const
        {
            return ((UInt8)(B * 255.0f)) << 24 |
                   ((UInt8)(G * 255.0f)) << 16 |
                   ((UInt8)(R * 255.0f)) <<  8 |
                   ((UInt8)(A * 255.0f));
        }

        inline void FromUInt32(UInt32 c)
        {
            R = (Float32)((c & 0xFF000000) >> 24) / 255.0f;
            G = (Float32)((c & 0x00FF0000) >> 16) / 255.0f;
            B = (Float32)((c & 0x0000FF00) >>  8) / 255.0f;
            A = (Float32)((c & 0x000000FF))       / 255.0f;
        }

        inline Color4 operator + (const Color4 &c) const
        {
            return Color4(R + c.R, G + c.G, B + c.B, A + c.A);
        }

        inline Color4 operator - (const Color4 &c) const
        {
            return Color4(R - c.R, G - c.G, B - c.B, A - c.A);
        }

        inline Color4 operator * (float f) const
        {
            return Color4(R * f, G * f, B * f, A * f);
        }

        inline Color4 operator / (float f) const
        {
            return Color4(R / f, G / f, B / f, A / f);
        }

        inline Color4& operator += (const Color4 &c)
        {
            R += c.R;
            G += c.G;
            B += c.B;
            A += c.A;

            return *this;
        }

        inline Color4& operator -= (const Color4 &c)
        {
            R -= c.R;
            G -= c.G;
            B -= c.B;
            A -= c.A;

            return *this;
        }

        inline Color4& operator *= (float f)
        {
            R *= f;
            G *= f;
            B *= f;
            A *= f;

            return *this;
        }

        inline bool operator == (const Color4 &c) const
        {
            return R == c.R && G == c.G && B == c.B && A == c.A;
        }

        inline bool operator != (const Color4 &c) const
        {
            return R != c.R || G != c.G || B != c.B || A != c.A;
        }
    };
}

# endif